package cn.uniquetech;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import cn.uniquetech.util.StrUtil;
import cn.uniquetech.yj.YJUtil;

public class GenYJUtil {
	private static final String PACKAGENAME = "cn.uniquetech";
	private static final String URL = "jdbc:db2://11.24.49.2:50000/PBCPMS3";
	private static final String NAME = "db2admin";
	private static final String PASS = "db2admin";
	private static final String DRIVER = "com.ibm.db2.jcc.DB2Driver";

	private List<String> tableNames;

	public GenYJUtil() {
		try {
			tableNames = new ArrayList<String>();
			tableNames.add("hldworkplans");
			Class.forName(DRIVER);
			Connection con = DriverManager.getConnection(URL, NAME, PASS);
			PreparedStatement ps = null;
			ResultSet rs = null;

			List<String> fields = new ArrayList<String>();
			List<String> fieldTypes = new ArrayList<String>();
			List<String> remarks = new ArrayList<String>();

			for (String tableName : this.tableNames) {
				tableName=tableName.toLowerCase();
				ps = con.prepareStatement("select name,coltype,remarks from sysibm.syscolumns where TBNAME ='"+tableName.toUpperCase()+"' and TBCREATOR='DB2ADMIN' order by colno asc ");
				rs = ps.executeQuery();
				while (rs.next()) {
					fields.add(rs.getString(1).toLowerCase().trim());
					fieldTypes.add(rs.getString(2).toLowerCase().trim());
					remarks.add(rs.getString(3));
				}
				String clazz = StrUtil.initCap(tableName);
				clazz = clazz.substring(0, clazz.length() - 1);
				String str = "";
				str = YJUtil.sc(PACKAGENAME, tableName, fields, fieldTypes,remarks, null);
				System.out.println(str);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new GenYJUtil();
	}

}
